package com.ds.lens.data.common.util;

import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class TimeUtils {
    private static DateTimeFormatter MINUTE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMdd HHmm")
            .withZone(ZoneOffset.UTC);

    public static long getTime(long finishTime) {
        ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(
                Instant.ofEpochMilli(finishTime), ZoneOffset.UTC);
        String zonedDateTimeStr = zonedDateTime.format(MINUTE_FORMAT);
        ZonedDateTime zonedDateTimeWithNoSeconds = ZonedDateTime.parse(zonedDateTimeStr, MINUTE_FORMAT);
        return Long.valueOf(zonedDateTimeWithNoSeconds.toInstant().toEpochMilli());
    }
}
